package scheduler

import (
	"github.com/robfig/cron"
	"github.com/sirupsen/logrus"
	"morleyStoneHome/config"
)

func Start() {
	c := cron.New()
	c1 := config.Instance.StakeCron
	c2 := config.Instance.RewardCron
	c3 := config.Instance.LifeCron
	c4 := config.Instance.WithdrawCron
	addCronFunc(c, c1, func() {
		handleStake()
	})
	addCronFunc(c, c2, func() {
		handleReward()
	})
	addCronFunc(c, c3, func() {
		handleLife()
	})
	addCronFunc(c, c4, func() {
		handleWithdraw()
	})
	c.Start()
}

func addCronFunc(c *cron.Cron, sepc string, cmd func()) {
	err := c.AddFunc(sepc, cmd)
	if err != nil {
		logrus.Error(err)
	}
}
